package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2023/8/10 15:24
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增套餐")
    @CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
    public Result saveSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.saveSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(("套餐分页查询"))
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        return Result.success(setmealService.pageQuery(setmealPageQueryDTO));
    }

    /**
     * 根据id进行套餐删除
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("根据id进行套餐删除")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result deleteSetmeal(Long[] ids){
        Result result = setmealService.deleteSetmeal(ids);
        return result;
    }

    /**
     * 根据id获取套餐信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id获取套餐信息")
    public Result<SetmealVO> selectSetmealById(@PathVariable("id") Long id){
        return Result.success(setmealService.selectSetmealById(id));
    }

    /**
     * 修改套餐信息
     * @param setmealDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐信息")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result updateSetmealById(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmealById(setmealDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("根据id进行套餐状态的修改")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result updateStatusById(@PathVariable("status")Integer status,Long id){
        return setmealService.updateStatusById(status,id);
    }


}
